package com.hzlj.position.locate.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.fz.common.base.dto.PageParamDTO;
import com.fz.common.base.dto.QueryPageResultDTO;
import com.fz.common.base.exception.PubError;
import com.fz.common.base.exception.PubException;
import com.fz.common.dict.annotation.DictConvert;
import com.hzlj.position.locate.common.dto.amtStatJzryReportAudio.AmtStatJzryReportAudioHandleDTO;
import com.hzlj.position.locate.common.dto.amtStatJzryReportAudio.AmtStatJzryReportAudioQueryParamDTO;
import com.hzlj.position.locate.common.dto.amtStatJzryReportAudio.AmtStatJzryReportAudioQueryResultDTO;
import com.hzlj.position.locate.common.model.AmtStatJzryReportAudio;
import com.hzlj.position.locate.dao.AmtStatJzryReportAudioDao;
import com.hzlj.position.locate.service.AmtStatJzryReportAudioService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 语音汇报-按人按月统计(AmtStatJzryReportAudio)表服务接口
 *
 * @author makejava
 * @date 2024-09-06 10:49:07
 */
@Slf4j
@Service
public class AmtStatJzryReportAudioServiceImpl implements AmtStatJzryReportAudioService {
    @Resource
    private AmtStatJzryReportAudioDao amtStatJzryReportAudioDao;

    /**
     * 通过id查询单条数据
     */
    @Override
    @DictConvert
    public AmtStatJzryReportAudioQueryResultDTO getAmtStatJzryReportAudioById(Integer id) {
        AmtStatJzryReportAudio amtStatJzryReportAudio = this.amtStatJzryReportAudioDao.getById(id);
        if (Objects.isNull(amtStatJzryReportAudio)) {
            throw new PubException(PubError.NO_OBJECT_FOUND);
        }
        return BeanUtil.copyProperties(amtStatJzryReportAudio, AmtStatJzryReportAudioQueryResultDTO.class);
    }

    /**
     * 查询列表：不分页
     */
    @Override
    @DictConvert
    public List<AmtStatJzryReportAudioQueryResultDTO> listAmtStatJzryReportAudio(AmtStatJzryReportAudioQueryParamDTO dto) {
        return this.amtStatJzryReportAudioDao.listAmtStatJzryReportAudio(dto);
    }

    /**
     * 查询列表：分页
     */
    @Override
    @DictConvert
    public QueryPageResultDTO<AmtStatJzryReportAudioQueryResultDTO> pageAmtStatJzryReportAudio(AmtStatJzryReportAudioQueryParamDTO dto, PageParamDTO page) {
        return this.amtStatJzryReportAudioDao.pageAmtStatJzryReportAudio(dto, page);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void handle(AmtStatJzryReportAudioHandleDTO dto) {
        for (AmtStatJzryReportAudioHandleDTO.Key key : dto.getKeys()) {
            amtStatJzryReportAudioDao.handle(dto, key);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void handlePhone(AmtStatJzryReportAudioHandleDTO dto) {
        for (AmtStatJzryReportAudioHandleDTO.Key key : dto.getKeys()) {
            amtStatJzryReportAudioDao.handlePhone(dto, key);
        }
    }
}
